package net.oschina.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import uk.co.senab.photoview.PhotoView;

/**
 * Created by wei03 on 2017/1/16.
 */
public class FriendsAdapter extends BaseAdapter {


    public FriendsAdapter(Context context) {
        mContext = context;
    }

    private Context mContext;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_friend, parent, false);
        FriendsHolder friendsHolder = new FriendsHolder(view);
        return friendsHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActiveBean activeBean = (ActiveBean) mDatas.get(position);
        FriendsHolder friendsHolder = (FriendsHolder) holder;
        Glide.with(CommonUtils.getContext()).load(activeBean.getPortrait()).into(friendsHolder.mIvIcont);
        friendsHolder.mTvUserName.setText(activeBean.getAuthor());
        friendsHolder.mTvTime.setText(activeBean.getPubDate());
        //富文本展示
        CommonUtils.displayRichText(mContext, activeBean.getMessage(), friendsHolder.mTvDes1);
        //friendsHolder.mTvDes1.setText(Html.fromHtml(activeBean.getMessage()));
        if (activeBean.getTweetimage() != null) {
            friendsHolder.mIvPhoto.setVisibility(View.VISIBLE);
            Glide.with(CommonUtils.getContext()).load(activeBean.getTweetimage()).into(friendsHolder.mIvPhoto);
        }else {
            friendsHolder.mIvPhoto.setVisibility(View.GONE);
        }
    }


    static class FriendsHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_icont)
        CircleImageView mIvIcont;
        @BindView(R.id.tv_userName)
        TextView mTvUserName;
        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv)
        TextView mTv;
        @BindView(R.id.tv_des1)
        TextView mTvDes1;
        @BindView(R.id.tv_des2)
        TextView mTvDes2;
        @BindView(R.id.iv_photo)
        PhotoView mIvPhoto;

        FriendsHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
